約 1,193,556 件
https://w.atwiki.jp/oit-archive/pages/27.html
worke1.c #include stdio.h #define KETA 12 int main(void){ /* 整数8421065536の多倍長数表現 */ int a[KETA] = {0, 0, 8, 4, 2, 1, 0, 6, 5, 5, 3, 6}; int b[KETA]; int i; /* 多倍長数aを多倍長数bにコピーする */ for (i=0; i KETA; i++){ b[i] = a[i]; } /* 配列bの内容を表示する */ printf("b = "); for (i=0; i KETA; i++){ printf("%d", b[i]); } printf("\n"); return 0;} worke2.c #include stdio.h #define KETA 12 /* 多倍長数の桁数 */int main(void){ int a[KETA]; int i; /* 多倍長数aをキーボードから入力 */ printf("Input a "); for (i=0; i KETA; i++){ scanf("%d", a[i]); } /* 多倍長数aを表示 */ printf("a = "); i=0; while (a[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", a[i]); i++; } printf("\n"); return 0;} worke3.c #include stdio.h #define KETA 12 /* 多倍長数の桁数 */int main(void){ int a[KETA] = {0, 0, 8, 4, 2, 1, 0, 6, 5, 5, 3, 6}; int b[KETA] = {0, 0, 8, 6, 4, 2, 0, 9, 7, 5, 3, 1}; int c[KETA]; int i, tmp; int carry = 0; /* 下位からの繰り上がり */ /* 多倍長数(c)←多倍長数(a)+多倍長数(b) */ carry = 0; for (i=KETA-1; i =0; i--){ tmp = a[i] + b[i] + carry; c[i] = tmp % 10; carry = tmp / 10; } /******** 別解 **************** for (i=0; i KETA; i++){ c[i] = a[i] + b[i]; } for (i=KETA-1; i =1; i--){ c[i-1] = c[i-1] + c[i]/10; c[i] = c[i] % 10; } ******** ここまで別解 ********/ /* cの内容を出力(課題2を再利用) */ printf("c = "); i=0; while (c[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", c[i]); i++; } printf("\n"); return 0;} worke4.c #include stdio.h #define KETA 12 /* 多倍長数の桁数 */int main(void){ int a[KETA] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0}; int b[KETA] = {0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; int i; /* 多倍長数(a) ← 多倍長数(a) - 多倍長数(b) */ for (i=KETA-1; i =0; i--){ a[i] = a[i] - b[i]; if (a[i] 0){ /* (注意)(a bを仮定しているので, 添字(i-1)が負になることは無い */ a[i-1]--; a[i] = a[i] + 10; } } /* aの内容を出力(課題2を再利用) */ printf("a = "); i=0; while (a[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", a[i]); i++; } printf("\n"); return 0;} worke5.c #include stdio.h #define KETA 12 /* 多倍長数の桁数 */int main(void){ int a[KETA] = {0, 0, 0, 0, 0, 0, 0, 6, 5, 5, 3, 6}; int x = 35; int i; int tmp; int carry = 0; /* 下位からの繰り上がり */ /* 多倍長数(a) ← 多倍長数(a) * int型(x) */ for (i=KETA-1; i =0; i--){ tmp = a[i] * x + carry; a[i] = tmp % 10; carry = tmp / 10; } /******** 別解 ******** for (i=0; i KETA; i++){ a[i] = a[i] * x; } for (i=KETA-1; i =1; i--){ a[i-1] = a[i-1] + a[i]/10; a[i] = a[i] % 10; } ******** ここまで別解 ********/ /* aの内容を出力(課題2を再利用) */ printf("a = "); i=0; while (a[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", a[i]); i++; } printf("\n"); return 0;} worke6.c #include stdio.h #define KETA 100 /* 多倍長数の桁数 */#define N 50 /* 1からNまでの階乗を計算する */ int main(void){ int fact[KETA] = {0}; int i; /* 多倍長数を操作するときのループ変数 */ int n; /* 1からNまでの階乗を計算するときのループ変数 */ int tmp; int carry = 0; /* 多倍長数factを1に設定する.配列の宣言時に全要素を0で 初期化しているので,末尾要素に1を格納するのみでよい.*/ fact[KETA-1] = 1; for (n=1; n =N; n++){ /* 多倍長数(fact) ← 多倍長数(fact) * int型(n) (課題5のプログラムを再利用) */ for (i=KETA-1; i =0; i--){ tmp = fact[i] * n + carry; fact[i] = tmp % 10; carry = tmp / 10; } /* 多倍長数aを表示(課題2のプログラムを再利用) */ printf("%2d! = ", n); i=0; while (fact[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", fact[i]); i++; } printf("\n"); } return 0;} worke7.c #include stdio.h #define KETA 12int main(void){ int a[KETA] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1}; int x = 365; int i; int tmp; /* 多倍長数(a) ← 多倍長数(a) ÷ int型(x) */ tmp = 0; for (i=0; i KETA; i++){ tmp = tmp*10 + a[i]; a[i] = tmp / x; tmp = tmp % x; } /* 多倍長数aを表示(課題2を再利用) */ printf("a = "); i=0; while (a[i]==0 i =KETA-2){ i++; } while (i KETA){ printf("%d", a[i]); i++; } printf("\n"); return 0;}
https://w.atwiki.jp/langc/pages/29.html
名前 コメント Exersixe 4-10.An alternate organization uses getline to read an entire input line; this makes getch and ungetch unnecessary. Revise the calculator to use this approach. //ぐちゃぐちゃですみません。。 //一行入力をバッファに取り込み、それをトークンに変換しながらキューに入れていき、 //トークンを要求されたら、キューから一つ取り出して返すようにしています。 #include stdio.h #include stdlib.h //for atof #include ctype.h //for getop #include math.h static enum { MAXOP = 100, NUMBER = 0, OP = 1, COM = 2, VAL = 3, OTHER = 4, MAXLINE = 100, MAXVAL = 100, BUFSIZE = 100, MAXSIZE = 100, IDT_SIZE = 13}; static int getop(char []); static void push(double); static double pop(); static int getSp(void); static void setSp(int); int pr4_10() { int type; double op1,op2; double tmp1, tmp2; char s[MAXOP]; double val[26] = {0}; double recentVal; while((type = getop(s)) != EOF) { //printf("type %d\n", type); //printf("s %s\n", s); switch (type) { case NUMBER push(atof(s)); break; case OP if(!strcmp(s, "sin")) push(sin(pop())); else if(!strcmp(s, "cos")) push(cos(pop())); else if(!strcmp(s, "tan")) push(tan(pop())); else if(!strcmp(s, "exp")) push(exp(pop())); break; case COM if(!strcmp(s, "print")) { //print the top element of the stack without popping tmp1 = pop(); push(tmp1); printf("\t%.8g\n", tmp1); } else if(!strcmp(s, "dup")) { //duplicate the top element of the stack tmp1 = pop(); push(tmp1); push(tmp1); } else if(!strcmp(s, "swap")) { //swap the top two elements tmp1 = pop(); tmp2 = pop(); push(tmp1); push(tmp2); } else if(!strcmp(s, "clear")) { //clear the stack setSp(0); } else if(!strcmp(s, "set")) { //set number to variable double value = pop(); int addr = (int)pop(); val[addr] = value; push(value); } else if(!strcmp(s, "get")) { //get number of variable int addr = (int)pop(); push(val[addr]); recentVal = val[addr]; //set recentVal } break; case a case b case c case d case e push(type- a ); //set addr break; case + push(pop() + pop()); break; case * push(pop() * pop()); break; case - op2 = pop(); push(pop() - op2); break; case / op2 = pop(); if(op2 != 0.0) push(pop() / op2); else printf("error zero divisor\n"); break; case % op2 = pop(); if(op2 != 0.0) push(fmod(pop(), op2)); else printf("error zero modulus\n"); break; case \n printf("\t%.8g\n", pop()); break; default printf("error unknown command %s\n", s); break; } } return 0; } static int sp = 0; static double val[MAXVAL]; static int getSp(void) { return sp; } static void setSp(int val) { sp = val; } // push push f to val of stack void push(double f) { if (sp MAXVAL) val[sp++] = f; else printf("error stack full, can t push %g\n", f); } //pop pop the top of val of stack and return double pop(void) { if(sp 0) return val[--sp]; else { printf("error stack empty\n"); return 0.0; } } //ID_entry typedef struct ID_entry { char *name_ptr; int len; struct ID_entry *next; } ID_entry; static ID_entry *IDTable[IDT_SIZE]; static int hash(char *sp) { unsigned h, g; for(h = 0; *sp != \0 ; sp++) { h = (h 4) + (unsigned)(*sp); if (g = h 0xf0000000) h = (h ^ g 24) ^ g; } return (h % IDT_SIZE); } char *IDentry(char *sp, int len) { int hval = hash(sp); ID_entry *np; for (np = IDTable[hval]; np != NULL; np = np- next) if((np- len) == len strcmp(np- name_ptr, sp) == 0) return np- name_ptr; np = (ID_entry *)malloc(sizeof(ID_entry)); np- name_ptr = (char *)malloc(len+1); np- len = len; np- next = IDTable[hval]; IDTable[hval] = np; return strcpy(np- name_ptr, sp); } //queue of Token typedef struct _token{ int symbol; char *name_ptr; } Token; Token queue[MAXSIZE]; int head = 0, tail = 0; int queuein(int sym, char *name) { if((tail+1) % MAXSIZE != head) { queue[tail].symbol = sym; queue[tail].name_ptr = name; tail++; tail = tail % MAXSIZE; return 0; } else return -1; } int queueout(int *sym, char **name) { if (tail != head) { int i,n; n = strlen(queue[head].name_ptr); *sym = queue[head].symbol; *name = queue[head].name_ptr; head++; head = head % MAXSIZE; return 0; } else return -1; } static int getline(char s[], int lim) { int c, i; i = 0; while(--lim 0 (c =getchar()) != EOF c != \n ) s[i++] = c; if (c == \n ) s[i++] = c; s[i] = \0 ; return i; } //getop get next operator or number of operand int getop(char s[]) { int i, c, next, index; int n; int sym; char tmp[MAXLINE]; char *id; char buf[MAXLINE]; if(queueout( sym, id) != -1) { //out queue if(sym == OTHER) { return id[0]; } else { strcpy(s, id); return sym; } } else { //set queue //一行よみこみ、トークンの列にする n = getline(buf, BUFSIZE); //get input size if(n == 0) { //input EOF only return EOF; } for(index = 0; index n; index++) { int tmpptr = 0; for(; (buf[index] == || buf[index] == \t ) index n; index++) //skip space and tab ; while((c = buf[index]) != c != \t c != \n c != \0 c != EOF) { tmp[tmpptr++] = buf[index++]; } if(c == \n ) { if(tmpptr == 0) { // \n だけの場合 tmp[tmpptr++] = \n ; tmp[tmpptr] = \0 ; id = IDentry(tmp, tmpptr+1); //名前表にとうろく queuein(OTHER, id); continue; } else { //別の文字列に \n がついていた場合 index--; //for next loop } } else if(c == EOF) { tmp[tmpptr++] = EOF; tmp[tmpptr] = \0 ; id = IDentry(tmp, tmpptr+1); queuein(OTHER, id); continue; } tmp[tmpptr] = \0 ; //only one alphabet if (!isdigit(tmp[0]) tmpptr == 1) { id = IDentry(tmp, tmpptr+1); queuein(OTHER, id); //not number continue; } //command if(!strcmp(tmp, "dup") || !strcmp(tmp, "print") || !strcmp(tmp, "swap") || !strcmp(tmp, "get") || !strcmp(tmp, "set") || !strcmp(tmp, "clear")) { id = IDentry(tmp, tmpptr+1); queuein(COM, id); continue; } //operator if(!strcmp(tmp, "+") || !strcmp(tmp, "-") || !strcmp(tmp, "*") || !strcmp(tmp, "/") || !strcmp(tmp, "%")) { id = IDentry(tmp, tmpptr+1); queuein(OTHER, id); continue; } if(!strcmp(tmp, "sin") || !strcmp(tmp, "cos") || !strcmp(tmp, "tan") || !strcmp(tmp, "exp") || !strcmp(tmp, "set") || !strcmp(tmp, "clear")) { id = IDentry(tmp, tmpptr+1); queuein(OP, id); continue; } //number id = IDentry(tmp, tmpptr+1); queuein(NUMBER, id); continue; } //トークンの値を一つ返す。 queueout( sym, id); if(sym == OTHER) { return id[0]; } else { int i, size; size = strlen(id); for(i = 0; i = size; i++) { s[i] = id[i]; } return sym; } } } Exersixe 4-11.Modify getop so that it doesn t need to use ungetch. Hint use an internal static variable. 偶然ungetchを使わずに組んでいたので、4-10のプログラムと同様です。 Exersixe 4-12.Adapt the ideas of printd to write a recursive version of itoa ; that is, convert an integer into a string by calling a recursive routine. Exersixe 4-13.Write a recursive version of the function reverse(s) , which reverses the string s in place. Exersixe 4-14.Define a macro swap(t,x,y) that interchanges two arguments of type t . (Block structure will help.)
https://w.atwiki.jp/irissetlist/pages/57.html
【福岡】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【北海道】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【宮城】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【大阪】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【愛知】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【東京】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~ 【まとめ】i☆Ris 2nd Live Tour 2016 ~Th!s !s i☆Ris!!~
https://w.atwiki.jp/oit-archive/pages/25.html
workc1.c #include stdio.h #define MEIJI_GANNEN 1868#define TAISHO_GANNEN 1912#define SHOWA_GANNEN 1926 #define HEISEI_GANNEN 1989 int main(void){ int year, gen, n; printf("明治 1 大正 2 昭和 3 平成 4:"); scanf("%d", gen); if( gen == 1 ){ printf("明治 "); year = MEIJI_GANNEN; } else if( gen == 2 ){ printf("大正 "); year = TAISHO_GANNEN; } else if( gen == 3 ){ printf("昭和 "); year = SHOWA_GANNEN; } else if( gen == 4 ){ printf("平成 "); year = HEISEI_GANNEN; } else { printf("元号が正しくありません。\n"); return 0; } printf("何年ですか?"); scanf("%d", n); year = year + (n-1); printf("西暦 %d 年です。\n", year); return 0;} workc2.c #include stdio.h int main(void) { int n; int w; /* 前回の1の位の値を格納 */ int flag; /* 1=昇順である, 0=昇順でない */ printf("数値を入力してください:"); scanf("%d", n); if(n 0){ printf("負の値です。\n"); return 0; } flag = 1; while( n 0 flag != 0){ w = n % 10; n = n / 10; if( n % 10 w ){ /* n%10‥今の1の位, w‥前の1の位 */ flag = 0; } } if(flag == 1){ printf("数字は昇順の並びです。\n"); } else { printf("数字は昇順の並びではありません。\n"); } return 0;} workc3.c #include stdio.h #define MAXARRAY 8 int main(void){ int i, j, mx, tmp; int data[] = {3, 4, 5, 3, 9 , 2, 7, 1}; printf("ソート前\n"); for(i=0; i MAXARRAY; i++){ printf("%d ",data[i]); } printf("\n"); for(i=0;i MAXARRAY -1; i++){ mx = i; for( j=i+1; j MAXARRAY; j++){ if( data[mx] data[j] ){ mx = j; } } tmp = data[i]; data[i] = data[mx]; data[mx] = tmp; } printf("ソート後\n"); for(i=0; i MAXARRAY; i++){ printf("%d ",data[i]); } printf("\n"); return 0;} workc4.c #include stdio.h #define MAXARRAY 8 void printArray( int d[], int n){ int i; for(i=0; i n; i++){ printf("%d ",d[i]); } printf("\n");} int selectionDecendSort(int d[], int n){ int i,j,mx,tmp; int count=0; for(i=0;i n -1; i++){ mx = i; for( j=i+1; j n; j++){ if( d[mx] d[j] ){ mx = j; count++; } } tmp = d[i]; d[i] = d[mx]; d[mx] = tmp; } return count;} int main(void){ int i; int c; int data[MAXARRAY]; printf("配列要素を入力してください:\n"); for( i=0; i MAXARRAY; i++){ scanf("%d", data[i]); } printf("ソート前\n"); printArray(data, MAXARRAY); c = selectionDecendSort(data, MAXARRAY); printf("ソート後\n"); printArray(data, MAXARRAY); printf("最大値交換回数 = %d\n", c); return 0;} workc5.c #include stdio.h #define BATCH 350 int main(void){ int total = 0; int c, n, r; int nokori; printf("1袋あたりの量:"); scanf("%d", n); c = 0; while( total+n = BATCH ){ total = total + n; c++; } r = BATCH - total; if( r == 0) { printf("1:原材料 %d 袋を取り出します。\n", c); printf("2:すべて投入します。\n"); } else { printf("1:原材料 %d 袋を取り出します。\n", c+1 ); printf("2:%d 袋は全て投入し、最後の1袋は %d gだけ量って投入します。\n", c , r); nokori = n - r; printf("3:原材料の残りは、%d gとなります。\n", nokori); } return 0;} workc6.c #include stdio.h #define BATCH 350 int main(void){ int total = 0; int c, n, r, m,i; int nokori; printf("1袋あたりの量 "); scanf("%d", n); printf("繰り返し数 "); scanf("%d", m); c = 0; for( i = 0; i m ; i++){ printf(" %d回目 \n",i+1); while( total+n = BATCH ){ total += n; c++; } r = BATCH - total; if(r == 0) { printf("1:原材料 %d 袋を取り出します。\n", c); printf("2:すべて投入します。\n"); nokori = 0; }else{ printf("1:原材料 %d 袋を取り出します。\n", c+1 ); printf("2:%d 袋は全て投入し、最後の1袋は %d gだけ量って投入します。\n", c , r); nokori = n - r; printf("3:原材料の残りは、%d gとなります。\n", nokori); } total = nokori; c = 0; } return 0; } workc7.c #include stdio.h #define BATCH 350 int calcInput(int nokori1, int n1){ int c1 = 0; while( nokori1 + n1 = BATCH ){ nokori1 += n1; c1++; } return c1;} int printMSG(int n2, int r2, int c2){ int rest; if( r2 == 0) { printf("1:原材料 %d 袋を取り出します。\n", c2); printf("2:すべて投入します。\n"); rest = 0; } else { printf("1:原材料 %d 袋を取り出します。\n", c2+1); printf("2:%d 袋は全て投入し、最後の1袋は %d gだけ量って投入します。\n", c2 , r2); rest = n2 - r2; printf("3:原材料の残りは、%d gとなります。\n", rest); } return rest;} int main(void){ int nokori = 0; int c, n, r, m,i; printf("1袋あたりの量 "); scanf("%d", n); printf("繰り返し数 "); scanf("%d", m); for( i = 0; i m ; i++){ printf(" %d回目 \n",i+1); c = calcInput(nokori, n); nokori = nokori + n * c; r = BATCH - nokori; nokori = printMSG(n, r, c); } return 0;} workc8.c #include stdio.h #define BATCH 350#define PACKSUU 3 /*価格 内容量の組合せ数*/ int calcInput(int nokori1, int n1){ int c1 = 0; while( nokori1 + n1 = BATCH ){ nokori1 += n1; c1++; } return c1;} int main(void) { int c, r0,r1, m,i,j; int totalp; int plist[PACKSUU] = { 315, 420, 730 }; /* 価格表*/ int vlist[PACKSUU]= { 175, 250, 500 }; /* 内容量*/ int tlist[PACKSUU]; int minprice=0, minpack=0; printf("繰り返し数 "); scanf("%d", m); for( j = 0; j PACKSUU; j++){ r0 =0; /* 前回の余り量 r0 今回の実行後の余り量 r1とする*/ totalp = 0; /* 費用の累積額の初期化*/ for( i = 0; i m ; i++){ c = calcInput(r0, vlist[j]); /* 袋まるごとの投入量計算*/ /* 部分的に投入する場合の量の計算 */ r1=BATCH - (vlist[j] * c + r0) ; if(r1 == 0){ r0 = 0; /* 余りが無い*/ totalp = totalp + c * plist[j]; }else { if( r0 = BATCH ){ r0 = vlist[j] - r1; /* 余りがあるが最後の袋の*/ totalp = totalp + (c+1) * plist[j]; /* 投入数が1増える*/ }else{ r0 = r0 - BATCH; /* 前回の残りで足りる場合。*/ } } } tlist[j]=totalp; /* totalp には使った袋の分の費用が入っている*/ if(j==0 || minprice totalp){ /*最小条件の更新*/ minprice = totalp; minpack = j; } } for( j = 0; j PACKSUU; j++){ printf("1袋 %d g では%d 円掛かります。\n",vlist[j], tlist[j]); } printf("よって1袋 %d gが最もお得です。\n",vlist[minpack]); return 0;}
https://w.atwiki.jp/oit-archive/pages/22.html
work91.c #include stdio.h #define NUMBER 8 int main(void){ int data[NUMBER]; int i; int sum; for (i=0; i NUMBER; i++){ scanf("%d", data[i]); } sum = 0; for (i=0; i NUMBER; i++){ sum = sum + data[i]; } printf("平均 %f\n", (double)sum/NUMBER); return 0;} work92.c #include stdio.h #define N 10 int main(void){ int a[N] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90}; int x, y; int tmp; printf("整数xを入力してください "); scanf("%d", x); printf("整数yを入力してください "); scanf("%d", y); printf("交換前 a[%d]=%d, a[%d]=%d\n", x, a[x], y, a[y]); tmp = a[x]; a[x] = a[y]; a[y] = tmp; printf("交換後 a[%d]=%d, a[%d]=%d\n", x, a[x], y, a[y]); return 0;} work93.c #include stdio.h #define N 12 int main(void){ int a[N] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110}; int i; int tmp; printf("配列a = "); for (i=0; i N; i++){ printf("%3d ", a[i]); } printf("\n"); for (i=0; i N-1-i; i++){ printf("a[%d]とa[%d]を交換します\n", i, N-1-i); tmp = a[i]; a[i] = a[N-1-i]; a[N-1-i] = tmp; } printf("配列a = "); for (i=0; i N; i++){ printf("%3d ", a[i]); } printf("\n"); return 0;} work94.c #include stdio.h #define N 5 int main(void){ int a[N] = {0, 10, 20, 30, 40}; int b[N] = {0, 10, 20, 30, 40}; int c[N] = {0, 10, 20, 30, 40}; int i; int cnt; int tmp; for (cnt=0; cnt N; cnt++){ /* 配列aを左シフト */ for (i=0; i N-1; i++){ a[i] = a[i+1]; } printf("%d回目 a = ", cnt+1); for (i=0; i N; i++){ printf("%2d ", a[i]); } printf("\n"); /* 配列bを右シフト */ for (i=N-1; i =1; i--){ b[i] = b[i-1]; } printf("%d回目 b = ", cnt+1); for (i=0; i N; i++){ printf("%2d ", b[i]); } printf("\n"); /* 配列cを循環右シフト */ tmp = c[N-1]; for (i=N-1; i =1; i--){ c[i] = c[i-1]; } c[0] = tmp; printf("%d回目 c = ", cnt+1); for (i=0; i N; i++){ printf("%2d ", c[i]); } printf("\n\n"); } return 0;} work95.c #include stdio.h #define MAXSIZE 10int main(void){ int a[MAXSIZE] = {10, 20, 30, 40, 50}; int index; /* キーボードから入力した添字を格納 */ int data; /* キーボードから入力した値を格納 */ int i; printf("a "); for (i=0; i MAXSIZE; i++){ printf("[%d]=%d ", i, a[i]); } printf("\n\n"); /* 1回目の入力 */ printf("index "); scanf("%d", index); printf("data "); scanf("%d", data); printf("a[%d]に%dを挿入します\n", index, data); /* 挿入 */ for (i=MAXSIZE-1; i index-1; i--){ a[i] = a[i-1]; } a[index] = data; printf("a "); for (i=0; i MAXSIZE; i++){ printf("[%d]=%d ", i, a[i]); } printf("\n\n"); /* 2回目の入力 */ printf("index "); scanf("%d", index); printf("a[%d]を削除します\n", index); /* 削除 */ for (i=index; i MAXSIZE-1; i++){ a[i] = a[i+1]; } a[MAXSIZE-1] = 0; printf("a "); for (i=0; i MAXSIZE; i++){ printf("[%d]=%d ", i, a[i]); } printf("\n"); return 0;} work96.c #include stdio.h #define N 10int main(void){ int a[N]; int i, j; int min_index; int tmp; for (i=0; i N; i++){ scanf("%d", a[i]); } /* iを0からN-1まで増やしながら,以下を繰り返す */ for (i=0; i N; i++){ /* a[i]?a[N-1]の中から最小値をもつ要素の添字を 見つけ,その添字をmin_indexに格納する */ min_index = i; for (j=i; j N; j++){ if (a[j] a[min_index]){ min_index = j; } } /* a[i]とa[min_index]を交換する */ tmp = a[i]; a[i] = a[min_index]; a[min_index] = tmp; } printf("配列a = "); for (i=0; i N; i++){ printf("%d ", a[i]); } printf("\n"); return 0;} work97.c #include stdio.h #define N 8 int main(void){ int data[N] = {10, 20, 30, 40, 50, 60, 70}; int i; int tmp; printf("data[%d] ", N-1); scanf("%2d", data[N-1]); printf("挿入前 "); for (i=0; i N; i++){ printf("%d ", data[i]); } printf("\n"); tmp = data[N-1]; for (i=N-2; i =0 tmp data[i]; i--){ data[i+1] = data[i]; } data[i+1] = tmp; printf("挿入後 "); for (i=0; i N; i++){ printf("%d ", data[i]); } printf("\n"); return 0;} work98.c #include stdio.h #define N 10int main(void){ int a[N]; int i, j; int tmp; for (i=0; i N; i++){ scanf("%d", a[i]); } /* 挿入ソート */ for (i=1; i N; i++){ tmp = a[i]; j=i-1; while (j =0 tmp a[j]){ a[j+1] = a[j]; j--; } a[j+1] = tmp; } printf("配列a = "); for (i=0; i N; i++){ printf("%d ", a[i]); } printf("\n"); return 0;} work99.c #include stdio.h #define N 8int main(void){ int a[N][N]; /* N×N行列 */ int b[N][N]; /* N×N行列 */ int c[N][N]; /* N×N行列 */ int i, j; /* N×N行列の初期設定 */ for (i=0; i N; i++){ for (j=0; j N; j++){ a[i][j] = i*N+j; b[i][j] = i+j; } } /* 行列和の計算 */ for (i=0; i N; i++){ for (j=0; j N; j++){ c[i][j] = a[i][j]+b[i][j]; } } for (i=0; i N; i++){ for (j=0; j N; j++){ printf("%3d ", c[i][j]); } printf("\n"); } return 0;}
https://w.atwiki.jp/also_little/pages/790.html
C・Sとは『かなり ショック』の略でトモのオリキャラのひとつである。
https://w.atwiki.jp/oit-archive/pages/18.html
work51.c #include stdio.h int main(void){ int a, b, c; int i; printf("初期値aの入力:"); scanf("%d", a); printf("条件(b以下)の入力:"); scanf("%d", b); printf("増分値cの入力:"); scanf("%d", c); for(i = a; i = b; i = i + c) printf("iの値は%dです。\n",i); return 0; } work52.c #include stdio.h int main(void){ int i, sum = 0; double ave; for(i = 1; i 11; i++) sum = sum + i; ave = (double) sum / 10; printf("数値の合計は%dです。\n", sum); printf("数値の平均は%.1fです。\n", ave); return 0; } work53.c #include stdio.h int main(void){ int a, i, sum = 0; double ave; for(i = 0; i 5; i++){ printf("数値を入力してください:"); scanf("%d", a); sum = sum + a; } ave = (double) sum / 5; printf("数値の合計は%dです。\n", sum); printf("数値の平均は%.1fです。\n", ave); return 0; } work54.c #include stdio.h int main(void){ int a, i, sum1 = 0, sum2 = 0, cnt1 = 0, cnt2 = 0; double ave1, ave2; for(i = 0; i 5; i++){ printf("数値を入力してください:"); scanf("%d", a); if(a 0) { sum1 = sum1 + a; cnt1++; } else { sum2 = sum2 + a; cnt2++; } } ave1 = (double) sum1 / cnt1; ave2 = (double) sum2 / cnt2; printf("正の数値の合計は%d、平均は%.1fです。\n", sum1, ave1); printf("それ以外の数値の合計は%d、平均は%.1fです。\n", sum2, ave2); return 0; } work55.c #include stdio.h int main(void){ int a, i; printf("星の数を入力してください:"); scanf("%d", a); printf("%d:",a); for(i = 1; i = a; i++){ if(i % 5 == 0 ) printf("☆"); else printf("★"); } printf("\n"); return 0; } work56.c #include stdio.h int main(void){ int a, b, i; int tmp, sum = 0; printf("一つ目の値の入力:"); scanf("%d", a); printf("二つ目の値の入力:"); scanf("%d", b); if(a b){ tmp = a; a = b; b = tmp; } for(i = a; i = b; i++) sum = sum + i * i; printf("%dから%dの平方和は%dです\n", a , b, sum); return 0; } work57.c #include stdio.h int main(void){ int a, b, i; int sum = 0, square = 0; double ave, sigma; printf("人数を入力して下さい:"); scanf("%d", a); for(i = 0; i a; i++){ printf("身長(cm)を入力してください:"); scanf("%d", b); sum = sum + b; square = square + b * b; } ave = (double) sum / a; sigma = (double) square / a - ave * ave; printf("入力した%d人の平均は%.2fです\n", a , ave); printf("入力した%d人の分散は%.2fです\n", a , sigma); return 0; } work58.c #include stdio.h int main(void){ int a, i; int fra = 1; printf("nの値を入力して下さい:"); scanf("%d", a); for(i = a; i 1; i--) fra = fra * i; printf("%dの階乗は%dです。\n", a, fra); return 0; } work59.c #include stdio.h int main(void){ int a, i; int sum1 = 0, sum2 = 0; int odd = 0, even = 0; double ave1, ave2; for(i = 0; i 5; i++){ printf("値を入力してください:"); scanf("%d", a); if(a % 2 == 1){ sum1 = sum1 + a; odd++; } else { sum2 = sum2 + a; even++; } } if(odd != 0){ ave1 = (double) sum1 / odd; printf("奇数の合計は%d、平均は%.2fです。\n", sum1, ave1); } else { printf("奇数の値は入力されませんでした。\n"); } if(even != 0){ ave2 = (double) sum2 / even; printf("偶数の合計は%d、平均は%.2fです。\n", sum2, ave2); } else { printf("偶数の値は入力されませんでした。\n"); } return 0; }
https://w.atwiki.jp/scarbateversion/pages/12.html
[S.C.a.R.]TRPGは当ページで無料公開しているTRPGシステムです。 まずはじめに 当サイトではオリジナルTRPGシステム『S.C.a.R.』を遊ぶために必要なルール、データ、テキストなどを提供している。 『S.C.a.R.』ではある日、無数の流星群が地上へ降り注ぎ、現代社会が崩壊した世界――いわゆる『ポストアポカリプス』を迎えた世界を舞台としたTRPGである。 世界各地に降り注いだ隕石の影響により、電気や水道などといったライフラインは断絶され、医療や治安というものは得難い貴重なものとなってしまった。 さらには各地で『マリグナント』と呼ばれる怪物たちが人々の生活を侵し始めたのだ。 人類はそんな世界で苦しみ怯えながらも今も生きている。 しかし、そんな脅威に対抗できる異能に目覚めた者がいる。 それが『スカード』と呼ばれる異能者たちだ。プレイヤーはこの『スカード』となり、この世界を生きていくことになる。
https://w.atwiki.jp/busphoto/pages/1018.html
社番 C838 メーカー いすゞ自動車 車名 エルガミオ 型式 KK-LR233J1 車体 IBUS 年式 2002. ステップ ワンステップ 転入年月 2016. 改番年月 - 前所属 松戸新京成バス 前社番 I-M27 登録番号 山梨200 か ・805 登録変更年月 - バックカメラ ○ ラッピング - 備考
https://w.atwiki.jp/oit-archive/pages/23.html
worka1.c #include stdio.h #include math.h int main(void){ double a, b, c; double x, y, z; double rad, pai = 3.14; printf("角度を入力して下さい:"); scanf("%lf", a); rad = a / 180 * pai; printf("%f度は%fラジアンです。\n", a, rad); x = cos(rad); printf("cos(%f)の値は%fです。\n", rad, x); x = tan(rad); printf("tan(%f)の値は%fです。\n\n", rad, x); printf("数値を入力して下さい:"); scanf("%lf", b); y = sqrt(b); printf("%fの平方根は%fです。\n\n", b, y); printf("数値を入力して下さい:"); scanf("%lf", c); z = log(c); printf("log(%.1f)の値は%fです。\n", c, z); z = log10(c); printf("log10(%.1f)の値は%fです。\n", c, z); return 0;} worka2.c #include stdio.h int add(int c, int d){ int e; e = c + d; return e;} int subtract(int c, int d){ int e; e = c - d; return e;} int multiple(int c, int d){ int e; e = c * d; return e;} double divide(int c, int d){ double e; e = (double)c / d; return e;} int main(void){ int a, b; int wa, sa, seki; double syou; printf("二つの数値を入力して下さい。\n"); printf("数値1:"); scanf("%d", a); printf("数値2:"); scanf("%d", b); wa = add(a, b); printf("%dに%dを加えると%dになります。\n", a, b, wa); sa = subtract(a, b); printf("%dから%dを引くと%dになります。\n", a, b, sa); seki = multiple(a, b); printf("%dに%dをかけると%dになります。\n", a, b, seki); syou = divide(a, b); printf("%dを%dで割ると%.3fになります。\n", a, b, syou); return 0;} worka3.c #include stdio.h int fact(int a){ int i; int fra = 1; for(i=1; i =a; i++){ fra = fra * i; } return fra;} int main(void){ int n, ans; printf("値を入力して下さい:"); scanf("%d", n); ans = fact(n); printf("%dの階乗は%dです。\n", n, ans); return 0;} worka4.c #include stdio.h void printStars(int a){ int i; printf("%2d ",a); for(i=1; i =a/10; i++){ printf("★"); } for(i=1; i =a%10; i++){ printf("☆"); } printf("\n"); return;} int main(void){ int i; int data[10] = {69, 63, 90, 58, 8, 22, 19, 20, 13, 74}; for(i=0; i 10; i++){ printf("%2d:", i+1); printStars(data[i]); } return 0;} worka5.c #include stdio.h int sumAtoB(int a, int b){ int i; int sum = 0; for(i = a; i = b; i++){ sum = sum + i; } return sum;} int main(void){ int start, end; int total; printf("開始値を入力して下さい:"); scanf("%d", start); printf("終了値を入力して下さい:"); scanf("%d", end); total = sumAtoB(start, end); printf("%dから%dまでの合計は%dです。\n", start, end, total); return 0;} worka6.c #include stdio.h double squareRoot(double a){ double root = 0.0; while(root * root a){ root = root + 0.0001; } if(root * root a + 0.0001){ root = root - 0.0001; } return root;} int main(void){ double inp, kon; printf("平方根を求める値の入力:"); scanf("%lf", inp); kon = squareRoot(inp); printf("%fの平方根は%.4fです。\n", inp, kon); return 0;} worka7.c #include stdio.h void BMIndex(int a, int b){ double bmi; bmi = (double) b * 10000 / (a * a); printf("あなたのBMI値は %.1f です。\n", bmi); if(bmi 18.5){ printf("肥満度は、やせです。\n"); }else if(bmi 25.0){ printf("肥満度は、標準です。\n"); }else if(bmi 30.0){ printf("肥満度は、肥満です。\n"); }else{ printf("肥満度は、過度肥満です。\n"); } return;} int main(void){ int height, weight; printf("身長(単位:cm)の入力:"); scanf("%d", height); printf("体重(単位:kg)の入力:"); scanf("%d", weight); BMIndex(height, weight); return 0;} worka8.c #include stdio.h int checkYear(int a){ int flag = 0; if(a % 4 == 0 a % 100 != 0 || a % 400 == 0) flag = 1; return flag;} int main(void){ int i, year1, year2; int flag = 0, cnt = 0; printf("西暦を入力して下さい:"); scanf("%d", year1); printf("西暦を入力して下さい:"); scanf("%d", year2); for(i = year1; i year2; i++){ flag = checkYear(i); if(flag == 1){ printf("%d年\n", i); cnt++; } } printf("閏年は%d回あります。\n", cnt); return 0;}